using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using ScriptEase.Shell.Controls;



namespace ScriptEase.Shell.Commands
{
    internal class ExploreDirectoryCommand : ICommand
    {
        private readonly ShellViewModel _shellViewModel;
        private readonly WebResourceStatusView _viewModel;



        public ExploreDirectoryCommand(ShellViewModel shellViewModel, WebResourceStatusView viewModel)
        {
            _shellViewModel = shellViewModel;
            _viewModel = viewModel;
        }



        public void Execute(object view)
        {
            List<MappingModel> selectedItems = _viewModel.SelectedItems.ToList();
            // if no file selected --> open project directory
            // else open the selected file's directory
            string directoryName = selectedItems.Count == 0 || selectedItems[0].FileInfo==null ? _shellViewModel.Project.ProjectDirectory : "\"" + selectedItems[0].FileInfo.Directory + "\"";
            PublicFunc.RunProcess("Explorer.exe", directoryName);
        }



        public bool CanExecute(object parameter)
        {
            return (_shellViewModel.ProjectLoadStatus != ProjectStatus.Closed);
        }



        public event EventHandler CanExecuteChanged;
    }
}